package thread;

// 1.继承Thread类
public class MyThread extends Thread{
	public MyThread(String name) {
		super(name);
	}

	// 2.重写run方法
	@Override
	public void run() {
		for (int i = 0; i < 100; i++) {
//			System.out.println(this.getName() +":" + i);
			System.out.println(Thread.currentThread().getName() + i);
			// 睡眠100毫秒
			try {
				Thread.sleep(100);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}
	
	public static void main(String[] args) {
		// 3.创建对象
		MyThread t = new MyThread("A:");
		// 设置守护线程，main不会等待守护线程
		t.setDaemon(true);
		// 4.启动线程
		t.start();
		
		for (int i = 0; i < 10; i++) {
			System.out.println("main:" + i);
			try {
				Thread.sleep(100);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}
}
